/**
 * Created by cleverdou on 2018/7/27.
 */
'use strict';

const {onlineSocketObj} = require("../mockSocket");
const envConfig = require("../env");

const express = require('express');
const router = express.Router();


/* GET users listing. */
router.get('/uploadDeviceIdentifier', function (req, res) {
    let socketKey = req.query.socketKey;
    const host = req.headers.host;
    if (socketKey === undefined) {
        res.send({
            "errorCode": "0000001",
            "data": {
                "total": 0
            },
            "succeed": false,
            "errorMessage": "socketKey非法"
        });
        return;
    }

    if (onlineSocketObj[socketKey] === undefined) {
        res.send({
            "errorCode": "0000001",
            "data": {
                "total": 0
            },
            "succeed": false,
            "errorMessage": "该对象不存在"
        });
        return;
    }

    res.send({
        "errorCode": "0000000",
        "data": {
            "total": 0,
            "proxyUrl": `http://${host}/${socketKey}`,
            "proxyWebUrl": `http://${host}/${socketKey}`
        },
        "succeed": true,
        "errorMessage": "操作成功"
    });
    onlineSocketObj[socketKey].emit('registDevice', true);
});

router.get('/envConfig', function (req, res) {
    res.send({
        "errorCode": "0000000",
        "data": envConfig,
        "succeed": true,
        "errorMessage": "操作成功"
    })
});


module.exports = router;
